package com.kinyx.framework.enums;

import java.util.Locale;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.enums.impl.ErrorCode0;
import com.kinyx.framework.enums.impl.ErrorCodeX;
import com.kinyx.framework.exception.KRuntimeException;

public class IErrorCodeEnum_Tester {

	@Test
	public void test() {
		// ErrorCodeX不做国际化处理
		Assert.assertEquals("never happens", new KRuntimeException(ErrorCodeX.NeverHappens).locale(null).getMessage());
		Assert.assertEquals("never happens", new KRuntimeException(ErrorCodeX.NeverHappens).locale(Locale.CHINESE).getMessage());
		Assert.assertEquals("never happens", new KRuntimeException(ErrorCodeX.NeverHappens).locale(Locale.SIMPLIFIED_CHINESE).getMessage());
		Assert.assertEquals("never happens", new KRuntimeException(ErrorCodeX.NeverHappens).locale(Locale.ENGLISH).getMessage());

		// 默认值
		Assert.assertEquals("can not convert type from [A] to [B]", new KRuntimeException(ErrorCode0.CanNotConvertType).locale(null).param("from", "A").param("to", "B").getMessage());
		// 精确匹配成功。
		Assert.assertEquals("can not convert type from [A] to [B]", new KRuntimeException(ErrorCode0.CanNotConvertType).locale(Locale.CHINESE).param("from", "A").param("to", "B").getMessage());
		// 精确匹配未成功，进行模糊匹配成功。
		Assert.assertEquals("can not convert type from [A] to [B]", new KRuntimeException(ErrorCode0.CanNotConvertType).locale(Locale.SIMPLIFIED_CHINESE).param("from", "A").param("to", "B").getMessage());
		// 精确匹配未成功，模糊匹配扔未成功，取默认值。
		Assert.assertEquals("can not convert type from [A] to [B]", new KRuntimeException(ErrorCode0.CanNotConvertType).locale(Locale.ENGLISH).param("from", "A").param("to", "B").getMessage());
	}

}
